package com.ctbri.containerindepth;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Ex6_Unsupported {

	public static void test(String msg, List<String> list) {
		System.out.println("------ " + msg + " ------");
		List<String> c = list;
		List<String> subList = list.subList(1, 8);
		List<String> c2 = new ArrayList<>(subList);
		try{
			c.add(0, "X");
		} catch(Exception e) {
			System.out.println("add(): " + e);
		}
		
		try {
			c.addAll(0, c2);
		} catch(Exception e) {
			System.out.println("addAll(): " + e);
		}
		
		try{
			c.remove(0);
		} catch(Exception e) {
			System.out.println("remove(): " + e);
		}
	}
	public static void main(String[] args) {
		List<String> list = Arrays.asList("A B C D E F G H I J K L".split(" "));
		test("Modifiable Copy", new ArrayList<>(list));
		test("Arrays.asList", list);
		test("unmodifiableList()", Collections.unmodifiableList(new ArrayList<>(list)));		
				
	}

}
